package com.kaola.service.impl;

import com.kaola.dao.AdminDAO;
import com.kaola.pojo.Admin;
import com.kaola.service.AdminService;

public class AdminServiceImpl implements AdminService {

	private AdminDAO adminDAO;

	public AdminDAO getAdminDAO() {
		return adminDAO;
	}

	public void setAdminDAO(AdminDAO adminDAO) {
		this.adminDAO = adminDAO;
	}

	public void add(Admin admin) {
		adminDAO.add(admin);
	}

	public Admin get(int id) {
		return adminDAO.get(id);
	}

	public Admin get(String account) {
		return adminDAO.get(account);
	}

	public void delete(int id) {
		adminDAO.delete(id);
	}

	public boolean validate(Admin admin) {
		Admin a = adminDAO.get(admin.getAccount());
		if (a != null) {
			if (a.getAccount().equals(admin.getAccount())
					&& a.getPassword().equals(admin.getPassword())) {
				return true;
			}
		}
		return false;
	}

	public boolean exist(String account) {
		if (adminDAO.get(account) != null) {
			return true;
		}
		return false;
	}
}
